package ai.people.netmon.warning.controller;

import ai.people.core.security.support.RequestHolderUtil;
import ai.people.netmon.framework.domain.warning.request.subject.AddSubjectRequest;
import ai.people.netmon.framework.domain.warning.request.subject.SubjectWarningRequest;
import ai.people.netmon.framework.domain.warning.request.subject.UpdateSubjectRequest;
import ai.people.netmon.framework.domain.warning.vo.MessageContentVO;
import ai.people.netmon.framework.domain.warning.vo.SubjectAnalysisVO;
import ai.people.netmon.framework.domain.warning.vo.WarningSubjectVO;
import ai.people.netmon.framework.model.response.PageResponse;
import ai.people.netmon.framework.model.response.Result;
import ai.people.netmon.framework.utils.ResultUtil;
import ai.people.netmon.warning.service.WarningSpeechTemplateService;
import ai.people.netmon.warning.service.WarningSubjectService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 主题预警接口
 *
 * @author yuanqinglong
 * @date 2022/7/27 14:31
 */
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/subject")
public class WarningSubjectController {

    /**
     * impl主题服务
     */
    private final WarningSubjectService warningSubjectService;

    /**
     * 主题impl预警服务
     */
    private final WarningSpeechTemplateService<SubjectWarningRequest, MessageContentVO> warningSubjectServiceImpl;


    /**
     * 主题预警信息列表
     *
     * @param subjectWarningRequest 受到警告请求
     * @return {@link Result}<{@link PageResponse}<{@link List}<{@link MessageContentVO}>>>
     */
    @PostMapping("/info/list")
    public Result<PageResponse<List<MessageContentVO>>> listSubjectWarning(@RequestBody SubjectWarningRequest subjectWarningRequest) {
        PageResponse<MessageContentVO> listPageResponse = warningSubjectServiceImpl.listMessages(subjectWarningRequest);
        return ResultUtil.success(listPageResponse);
    }


    /**
     * 添加主题
     *
     * @param addSubjectRequest 请求添加主题
     * @return {@link Result}<{@link Void}>
     */
    @PostMapping
    public Result<Void> addSubject(@Validated @RequestBody AddSubjectRequest addSubjectRequest){
        warningSubjectService.addSubject(addSubjectRequest);
        return ResultUtil.success();
    }


    /**
     * 主题分析菜单列表
     *
     * @return {@link Result}<{@link SubjectAnalysisVO}>
     */
    @PostMapping("/analysis/list")
    public Result<SubjectAnalysisVO> listSubjectAnalysis(){
        List<SubjectAnalysisVO> subjectAnalysis = warningSubjectService.listSubjectAnalysis(RequestHolderUtil.getUserId());
        return ResultUtil.success(subjectAnalysis);
    }


    /**
     * 更新主题
     *
     * @param updateSubjectRequest 更新主题要求
     * @return {@link Result}<{@link Void}>
     */
    @PutMapping
    public Result<Void> updateSubject(@Validated @RequestBody UpdateSubjectRequest updateSubjectRequest){
        warningSubjectService.updateSubject(updateSubjectRequest);
        return ResultUtil.success();
    }

    /**
     * 删除主题
     *
     * @param id id
     * @return {@link Result}<{@link Void}>
     */
    @DeleteMapping("/{id}")
    public Result<Void> deleteSubject(@PathVariable("id") Long id){
        warningSubjectService.deleteSubject(id);
        return ResultUtil.success();
    }

    /**
     * 获取主题信息
     *
     * @param id id
     * @return {@link Result}<{@link WarningSubjectVO}>
     */
    @GetMapping("/{id}")
    public Result<WarningSubjectVO> getSubject(@PathVariable("id") Long id){
        return ResultUtil.success(warningSubjectService.getSubject(id));
    }



}
